package org.su.generalmvc.jdbc;

import java.sql.SQLException;

/**
 * 数据库操作异常
 * 
 * @author yangchuan
 * @CreateTime 2010-8-21 下午05:08:42
 * 
 */
public class DBException extends RuntimeException {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public SQLException getSQLException() {
		return (SQLException)this.getCause();
	}

	public DBException(SQLException e) {
		super(e);
	}
	
	public DBException(String msg) {
		super(msg);
	}

	public DBException(String msg, SQLException e) {
		super(msg, e);
	}
	
	public DBException(SQLException e, String sql, Object... params) {
		super(e.getMessage() + "[" + sql + ":" + parmToString(params) + "]", e);
	}

	private static String parmToString(Object... params) {
		StringBuilder result = new StringBuilder();
		if (params != null && params.length > 0) {
			for (int i = 0; i < params.length; i++) {
				result.append(params[i]);
				result.append(',');
			}
		}
		return result.toString();
	}
}
